/*
 * IntSelector.java
 * 
 * last update: 16.01.2010 by Stefan Saru
 * 
 * author:	Alec(panovici@elcom.pub.ro)
 * 
 * Obs:
 */

package engine;

class IntSelector extends Expression implements LeftValue{

	BitVector b;
	GenericSelectorDescription desc; //runtime type info

	public IntSelector(NameSpace n, BitVector b, GenericSelectorDescription desc){
		super(n);
		this.b = b;
		this.desc = desc;
		length = b.n;
	}

	public void addMonitor(Monitor m){
		b.addMonitor(m);
	}

	//FIXME: de corectat: nu -si mareste lungimea dupa rezultat !
	public void assign(Result result)throws InterpretTimeException{
		BitVector val = result.getInt();
		if(length > val.n ) val.expandS(length);
		if(length < val.n ) val.trunc(length);
		try{
			b.attrib(val);
		}catch(Exception ex){
			if(xConsole.__debug__)ex.printStackTrace();
			throw new InterpretTimeException("invalid attribution: " + b + " = " + result);
		}
	}

	public Result evaluate(){
		return new BitVector(b);
	}

	public String toString(){
		return desc.toString();
	}

	public int length() {
		return length;
	}
}
